<template>
  <div class="expert-box">
    <el-tabs type="border-card">
      <el-tab-pane label="基本信息">
        <el-descriptions class="margin-top" :column="2" :size="size" border>
          <el-descriptions-item>
            <template slot="label"> 姓名 </template>
            <div class="display-notice">
              <el-input v-model="expertInfo.expertName"></el-input>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 性别 </template>
            <div class="display-notice">
              <el-radio
                label="1"
                style="margin-left: 20px"
                v-model="expertInfo.gender"
                >男</el-radio
              >
              <el-radio label="2" v-model="expertInfo.gender">女</el-radio>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 身份证号 </template>
            <div class="display-notice">
              <el-input v-model="expertInfo.idCard"></el-input>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 手机号 </template>
            <div class="display-notice">
              <el-input v-model="expertInfo.phone"></el-input>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 邮箱 </template>
            <div class="display-notice">
              <el-input v-model="expertInfo.email"></el-input>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 健康状况 </template>
            <div class="display-notice">
              <el-radio
                label="1"
                style="margin-left: 20px"
                v-model="expertInfo.health"
                >健康</el-radio
              >
              <el-radio label="2" v-model="expertInfo.health">不健康</el-radio>
            </div>
          </el-descriptions-item>

          <el-descriptions-item>
            <template slot="label"> 通讯地址 </template>
            <div class="display-notice">
              <el-input v-model="expertInfo.address"></el-input>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> </template>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 工作单位 </template>
            <div class="display-notice">
              <el-input v-model="expertInfo.workUnit"></el-input>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 所属类型 </template>
            <div>
              <el-select
                placeholder="请选择业务类型"
                clearable
                class="my_style"
                v-model="expertInfo.type"
              >
                <el-option
                  v-for="dict in dict.type.basic_expert_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 开户行 </template>
            <div class="display-notice">
              <el-input v-model="expertInfo.bank"></el-input>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 银行卡号 </template>
            <div class="display-notice">
              <el-input v-model="expertInfo.bankAccountNumber"></el-input>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 证件照 </template>
            <div class="display-notice">
              <imageUpload
                :cardMessage.sync="fileInfo"
                ref="imgChildren"
              ></imageUpload>
            </div>
          </el-descriptions-item>
        </el-descriptions>
        <div style="height: 130px">
          <el-button @click="updateExpert" type="primary" style="margin-left: 1100px; margin-top: 30px">修改</el-button>
          <el-button
            type="info"
           
            @click="back"
            >返 回</el-button
          >
        </div>
      </el-tab-pane>

    </el-tabs>
  </div>
</template>
  
  <script>
  import { updateExpert } from "@/api/expert/expert";
import { getPurCode, deleteFile } from "@/api/purs/purs";
import {
  addExpertFile,
  deleteBsExpertFiles,
  listExpertFile,
} from "@/api/basic/expertFile";
export default {
  dicts: ["basic_expert_type"],
  data() {
    return {
      fileInfo: {
        code: 1,
      },
      //基本信息
      expertInfo: {},
      size: "",
      expertFile: {},
      uploadFlag: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      fileList: [],
    };
  },
  watch: {
    fileInfo: {
      handler(value) {
        if (value.code == 1) {
          this.expertFile.expertCode = this.expertInfo.expertCode;
          this.expertFile.name = value.fileName;
          this.expertFile.url = value.filePath;
          addExpertFile(this.expertFile).then((res) => {
            if (res.code == 200) {
              this.uploadFlag = false;
              this.$modal.msgSuccess("上传成功");
            }
          });

     
        } else if (value.code == 2) {
          deleteFile(this.expertFile.name).then();
          deleteBsExpertFiles(this.expertFile.name).then((res) => {
            if (res.code == 200) {
              this.$modal.msgSuccess("删除成功");
            }
          });
        } else {
          deleteFile(value.name).then();
          deleteBsExpertFiles(value.name).then((res) => {
            if (res.code == 200) {
              this.$modal.msgSuccess("删除成功");
            }
          });
        }
      },
    },
  },
  created() {
    this.expertInfo = this.$route.query.obj;
    this.getFileList();
  },

  methods: {

    updateExpert(){
        updateExpert(this.expertInfo).then((res)=>{
          if(res.code==200){
            this.$modal.msgSuccess('修改成功');
            this.$router.back();
          }
          
        });
    },
    back() {
      this.$router.back();
    },

    getFileList() {
      this.queryParams.expertCode = this.expertInfo.expertCode;

      listExpertFile(this.queryParams).then((res) => {
        if (res.rows.length > 0) {
          this.fileList = [];
          res.rows.forEach((item) => {
            let obj = {};
            obj.url = item.url;
            obj.name = item.name;
            obj.code = 3;
            this.fileList.push(obj);
          });
        }
        this.$refs.imgChildren.setFileList(this.fileList);
      });
    },
  },
};
</script>
  
  <style scope>
.el-select-dropdown .el-select-dropdown__item {
  /* 设置字体颜色为黑色 (#333) */
  color: #409eff; /* 修改激活时的字体颜色 */
  font-weight: bold;
}

.display-notice .el-input input {
  border: none;
  outline: none;
  box-shadow: none;
}
</style>